package com.ruoyi.project.wechatprogram.categorymenu.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.categorymenu.domain.WxCategoryMenu;
import com.ruoyi.project.wechatprogram.categorymenu.service.IWxCategoryMenuService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 类型-菜品中间Controller
 * 
 * @author sxchen
 * @date 2020-04-23
 */
@Controller
@RequestMapping("/wechatprogram/categorymenu")
public class WxCategoryMenuController extends BaseController
{
    private String prefix = "wechatprogram/categorymenu";

    @Autowired
    private IWxCategoryMenuService wxCategoryMenuService;

    @RequiresPermissions("wechatprogram:categorymenu:view")
    @GetMapping()
    public String categorymenu()
    {
        return prefix + "/categorymenu";
    }

    /**
     * 查询类型-菜品中间列表
     */
    @RequiresPermissions("wechatprogram:categorymenu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxCategoryMenu wxCategoryMenu)
    {
        startPage();
        List<WxCategoryMenu> list = wxCategoryMenuService.selectWxCategoryMenuList(wxCategoryMenu);
        return getDataTable(list);
    }

    /**
     * 导出类型-菜品中间列表
     */
    @RequiresPermissions("wechatprogram:categorymenu:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxCategoryMenu wxCategoryMenu)
    {
        List<WxCategoryMenu> list = wxCategoryMenuService.selectWxCategoryMenuList(wxCategoryMenu);
        ExcelUtil<WxCategoryMenu> util = new ExcelUtil<WxCategoryMenu>(WxCategoryMenu.class);
        return util.exportExcel(list, "categorymenu");
    }

    /**
     * 新增类型-菜品中间
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存类型-菜品中间
     */
    @RequiresPermissions("wechatprogram:categorymenu:add")
    @Log(title = "类型-菜品中间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxCategoryMenu wxCategoryMenu)
    {
        return toAjax(wxCategoryMenuService.insertWxCategoryMenu(wxCategoryMenu));
    }

//    /**
//     * 修改类型-菜品中间
//     */
//    @GetMapping("/edit/{id}")
//    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
//    {
//        WxCategoryMenu wxCategoryMenu = wxCategoryMenuService.selectWxCategoryMenuById(id);
//        mmap.put("wxCategoryMenu", wxCategoryMenu);
//        return prefix + "/edit";
//    }

    /**
     * 修改保存类型-菜品中间
     */
    @RequiresPermissions("wechatprogram:categorymenu:edit")
    @Log(title = "类型-菜品中间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxCategoryMenu wxCategoryMenu)
    {
        return toAjax(wxCategoryMenuService.updateWxCategoryMenu(wxCategoryMenu));
    }

    /**
     * 删除类型-菜品中间
     */
    @RequiresPermissions("wechatprogram:categorymenu:remove")
    @Log(title = "类型-菜品中间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxCategoryMenuService.deleteWxCategoryMenuByIds(ids));
    }
}
